package leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * 汇总区间
 * @program: brushing
 * @description: https://leetcode-cn.com/problems/summary-ranges/
 * @author: LiuQiang
 * @create: 2019-04-04 15:35
 **/
public class SummaryRanges {

    public List<String> summaryRanges(int[] nums) {
        List<String> strList = new ArrayList<>();
        String s = "";
        boolean flag = false;
        for (int i = 0; i < nums.length; i++) {
            int num = nums[i];
            if (i + 1 < nums.length && num + 1 == nums[i+1]) {
                flag = true;
                if (s.length() <= 0 ){
                    s += String.valueOf(nums[i]) + "->";
                }
            } else {
                flag = false;
                s += String.valueOf(nums[i]);
                strList.add(s);
                s = "";
            }

        }


        return strList;
    }

    public static void main(String[] args) {
        SummaryRanges summaryRanges = new SummaryRanges();
        List<String> infoList = summaryRanges.summaryRanges(new int[]{-1});
        for (String s : infoList) {
            System.out.println(s);
        }
    }
}
